<?php

class Acl_Ips_Ip
{
	
	protected $db;
	protected $ip;
	protected $timeSeconds;
	
	function __construct($ip)
	{
		require ($_SERVER['DOCUMENT_ROOT'].'/../application/configs/settings.php');
		$this->db=Acl_Mysql_Connect::getInstance($database);
		$this->ip=$ip;
		// TODO: parametrizar
		$this->timeSeconds=60;		
	}
	
	/* pregunta a la lista negra */
	public function getIp()
	{
		$sql="SELECT ip,timestamp FROM blockedIps 
			  WHERE ip='".$this->ip."'";		
		$arrayIp=$this->db->fetchOneArray($sql);

		
		$timeout=time()-$arrayIp['timestamp'];
		
		/*No esta en la lista negra*/
		if($arrayIp['ip']==NULL)
			return FALSE;
		else
		{/* Esta en la lista negra */
			if($timeout>$this->timeSeconds)
			{
				/*Borrar Ip de lista negra*/
				$this->deleteIp();
				return FALSE;
			}
			else
			{	
				return $this->ip;
			}
		}
		
		
	}

	/* Inserta en la lista negra */	
	public function insertIp()
	{
		$sql="INSERT INTO blockedIps 
			SET ip='".$this->ip."'";
		$this->db->execute($sql);
		return;
	}
	
	/* Borra de la lista negra */
	public function deleteIp()
	{
		$sql="DELETE FROM blockedIps WHERE ip='".$this->ip."'"; 
		$this->db->execute($sql);
		return;
	}
	

	
	
	
	
	
}